import {security} from "../units/encrypt";
import {setValidator} from "../decorator/setValidator";
import {validatorEnum} from "../validator/validatorEnum";
import {getValidators} from "../decorator/getValidators";
import {mc_validatorResult} from "./mc_validatorResult";
/**
 * Created by ybjaa on 2017/4/21.
 *
 * 登录
 *
 * ms(实体类，和服务器交互的)
 *
 */
export class ms_loginUser{


    @setValidator(validatorEnum.regularFail,
        "用户名只能为字母和数字以及特殊字符，不能出现中文,空格等字符。",security.userNameRegexp)
    @setValidator(validatorEnum.maxAndMinLength,"用户名:长度不符合规定。",4,20)
    public userName:string="";


    @setValidator(validatorEnum.regularFail,
        "密码只能为字母和数字以及特殊字符，不能出现中文，空格等字符。",security.passwordRegexp)
    @setValidator(validatorEnum.maxAndMinLength,"密码:长度不符合规定。",6,20)
    public password:string="";


    /**
     * 对密码进行加密
     * 加密算法
     * MD5(password)+MD5(MD5(password))中，取偶数字符拼接后转为大写再次进行MD5运算
     * @returns {string}
     */
    encrypt():string{
        return security.encrypt(this.password.trim());
    }

    @getValidators()
    getValidator(result:boolean=null,result_validators:mc_validatorResult[]=null):mc_validatorResult{

        let messages="";

        if(!result){
            messages=result_validators.map(v=>v.message).join("\r\n");
        }

        let validatorResult=new mc_validatorResult();

        validatorResult.result=result;
        validatorResult.message=messages;

        return validatorResult;

    }

}